package com.ourteam.product.model.dao.impl;

import com.ourteam.product.model.dao.IProductDatabaseDataTypeMapDAO;
import com.ourteam.product.model.dao.ProductDatabaseDataTypeMap;
import com.ourteam.product.model.dao.ProductDatabaseDataTypeMapDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 IRKT 2017
 * Auto Generate Date : 2017-11-17 11:01:19
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractProductDatabaseDataTypeMapDAOJdbcImpl
    extends AbstractSpringDAO implements IProductDatabaseDataTypeMapDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, DataType, MappedDataType, Status, Remarks
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.DataType,
            _DataObjectProperty.MappedDataType, _DataObjectProperty.Status,
            _DataObjectProperty.Remarks
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<ProductDatabaseDataTypeMap, ProductDatabaseDataTypeMapDAOQueryBean> daoHelper;

    public AbstractProductDatabaseDataTypeMapDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<ProductDatabaseDataTypeMap, ProductDatabaseDataTypeMapDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aProductDatabaseDataTypeMap
         * @throws Exception
         */
    public boolean checkIsUnique(
        ProductDatabaseDataTypeMap aProductDatabaseDataTypeMap)
        throws Exception {
        if (aProductDatabaseDataTypeMap == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aProductDatabaseDataTypeMap.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aProductDatabaseDataTypeMap
     * @throws Exception
     */
    public void insert(ProductDatabaseDataTypeMap aProductDatabaseDataTypeMap)
        throws Exception {
        super.doInsert(aProductDatabaseDataTypeMap);
    }

    /**
         * Batch Insert Datas
         * @param aProductDatabaseDataTypeMap
         * @throws Exception
         */
    public void batchInsert(
        ProductDatabaseDataTypeMap[] aProductDatabaseDataTypeMaps)
        throws Exception {
        super.doBatchInsert(aProductDatabaseDataTypeMaps);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(ProductDatabaseDataTypeMapDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(ProductDatabaseDataTypeMap aProductDatabaseDataTypeMap)
        throws Exception {
        delete(aProductDatabaseDataTypeMap.getId());
    }

    /**
     * Update Data Selective
     * @param aProductDatabaseDataTypeMap
     * @throws Exception
     */
    public void update(ProductDatabaseDataTypeMap aProductDatabaseDataTypeMap)
        throws Exception {
        if (aProductDatabaseDataTypeMap.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aProductDatabaseDataTypeMap);

        ProductDatabaseDataTypeMap tempObj = findById(aProductDatabaseDataTypeMap.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aProductDatabaseDataTypeMap, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aProductDatabaseDataTypeMaps[]
     * @throws Exception
     */
    public void batchUpdate(
        ProductDatabaseDataTypeMap[] aProductDatabaseDataTypeMaps)
        throws Exception {
        super.doBatchUpdate(aProductDatabaseDataTypeMaps);
    }

    /**
         * Update Data By Condictions
         * @param aProductDatabaseDataTypeMap
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(ProductDatabaseDataTypeMap aProductDatabaseDataTypeMap,
        ProductDatabaseDataTypeMapDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aProductDatabaseDataTypeMap, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(ProductDatabaseDataTypeMapDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(
        ProductDatabaseDataTypeMap aProductDatabaseDataTypeMap)
        throws Exception {
        if (aProductDatabaseDataTypeMap.getDataType() == null) {
            throw new Exception(
                "The ProductDatabaseDataTypeMap.dataType value is not allow NULL");
        }

        if (aProductDatabaseDataTypeMap.getMappedDataType() == null) {
            throw new Exception(
                "The ProductDatabaseDataTypeMap.mappedDataType value is not allow NULL");
        }

        if (aProductDatabaseDataTypeMap.getStatus() == null) {
            throw new Exception(
                "The ProductDatabaseDataTypeMap.status value is not allow NULL");
        }

        if (aProductDatabaseDataTypeMap.getRemarks() == null) {
            throw new Exception(
                "The ProductDatabaseDataTypeMap.remarks value is not allow NULL");
        }
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public ProductDatabaseDataTypeMap findById(final long id)
        throws Exception {
        ProductDatabaseDataTypeMapDAOQueryBean queryBean = new ProductDatabaseDataTypeMapDAOQueryBean();

        ProductDatabaseDataTypeMapDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        ProductDatabaseDataTypeMap[] ProductDatabaseDataTypeMaps = query(queryBean);

        if (ProductDatabaseDataTypeMaps.length == 0) {
            return null;
        } else {
            return ProductDatabaseDataTypeMaps[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return ProductDatabaseDataTypeMap[]
         * @throws Exception
         */
    public ProductDatabaseDataTypeMap[] query(
        ProductDatabaseDataTypeMapDAOQueryBean queryBean)
        throws Exception {
        List result = super.doQuery(queryBean,
                new JdbcProductDatabaseDataTypeMapRowMapper());

        return (ProductDatabaseDataTypeMap[]) result.toArray(new ProductDatabaseDataTypeMap[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        ProductDatabaseDataTypeMapDAOQueryBean queryBean)
        throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(ProductDatabaseDataTypeMapDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(
        ProductDatabaseDataTypeMap[] aProductDatabaseDataTypeMaps,
        ProductDatabaseDataTypeMapDAOQueryBean queryBean)
        throws Exception {
        daoHelper.synchronize(aProductDatabaseDataTypeMaps, queryBean);
    }

    public void synchronize(
        ProductDatabaseDataTypeMap[] aProductDatabaseDataTypeMaps,
        ProductDatabaseDataTypeMapDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<ProductDatabaseDataTypeMap> callBack)
        throws Exception {
        daoHelper.synchronize(aProductDatabaseDataTypeMaps, queryBean, callBack);
    }

    public static class JdbcProductDatabaseDataTypeMapRowMapper
        implements RowMapper<ProductDatabaseDataTypeMap> {
        public ProductDatabaseDataTypeMap mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            ProductDatabaseDataTypeMap object = new ProductDatabaseDataTypeMap();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object dataType = null;

                dataType = resultSet.getObject(columnIndex++);

                object.setDataTypeNull(resultSet.getBoolean(columnIndex++));

                if (dataType != null) {
                    setBeanValue(object, _DataObjectProperty.DataType, dataType);
                }

                Object mappedDataType = null;

                mappedDataType = resultSet.getObject(columnIndex++);

                object.setMappedDataTypeNull(resultSet.getBoolean(columnIndex++));

                if (mappedDataType != null) {
                    setBeanValue(object, _DataObjectProperty.MappedDataType,
                        mappedDataType);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object remarks = null;

                remarks = resultSet.getObject(columnIndex++);

                object.setRemarksNull(resultSet.getBoolean(columnIndex++));

                if (remarks != null) {
                    setBeanValue(object, _DataObjectProperty.Remarks, remarks);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
